package com.honghu.villagepost.util;

import android.content.Intent;
import android.net.Uri;
import android.webkit.JavascriptInterface;

import com.blankj.utilcode.util.ToastUtils;
import com.honghu.villagepost.activity.LoginActivity;
import com.honghu.villagepost.base.BaseActivity;


/**
 * Copyright (c) 2015. LiaoPeiKun Inc. All rights reserved.
 */
@SuppressWarnings("unused")
public class WebViewOB {

    public static String EXTRA_WEBVIEW_TAG = "webViewTag";

    private BaseActivity mContext;

    public WebViewOB(BaseActivity context) {
        mContext = context;
    }

    /**
     * 显示Toast消息提示
     *
     * @param message
     */
    @JavascriptInterface
    public void showToast(String message) {
        ToastUtils.showShort(message);
    }

    /**
     * 打开登录页面
     */
    @JavascriptInterface
    public void toLogin() {
        Intent intent = new Intent(mContext, LoginActivity.class);
        mContext.startActivity(intent);
    }

    @JavascriptInterface
    public void joinQQGroup(String key) {
        Intent intent = new Intent();
        intent.setData(Uri.parse("mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26k%3D" + key));
        // 此Flag可根据具体产品需要自定义，如设置，则在加群界面按返回，返回手Q主界面，不设置，按返回会返回到呼起产品界面
        // intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        try {
            mContext.startActivity(intent);
        } catch (Exception e) {
            ToastUtils.showShort("未安装手机QQ");
        }
    }

}
